﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Seuss.EnterpriseLibrary.DataAccess
Imports Seuss.EnterpriseLibrary.BusinessLogic
Imports System.Web
Imports System.Data

Partial Class Consulta_PA_Eventos_Det
    Inherits System.Web.UI.Page
    Dim nUniOrgCodigo As Integer
    Dim cDocCodigo As String
    Dim cPerCodigo As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        nUniOrgCodigo = Request.QueryString("nUniOrgCodigo")
        cDocCodigo = Request.QueryString("cDocCodigo")
        cPerCodigo = Request.QueryString("cPerCodigo")
        Response.Expires = -1
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("cache-control", "private")
        Response.CacheControl = "no-cache"

        If Not Page.IsPostBack Then
            lblcPercodigo.Text = cPerCodigo
            If String.IsNullOrEmpty(cDocCodigo) Then
                lnkRegresar_1.HRef = "./PA_Eventos.aspx?cPerCodigo=" + lblcPercodigo.Text
                lnkRegresar_2.HRef = "./PA_Eventos.aspx?cPerCodigo=" + lblcPercodigo.Text
                MVEventos.ActiveViewIndex = 0
                Call CargarEventos(nUniOrgCodigo)
            Else
                lnkRegresar_1.HRef = "./PA_Eventos_Det.aspx?NuniOrgCodigo=" + nUniOrgCodigo.ToString + "&cPerCodigo=" + lblcPercodigo.Text
                lnkRegresar_2.HRef = "./PA_Eventos_Det.aspx?NuniOrgCodigo=" + nUniOrgCodigo.ToString + "&cPerCodigo=" + lblcPercodigo.Text
                MVEventos.ActiveViewIndex = 1
                Call CargarEventos_Detalle(cDocCodigo)
            End If
            Using Seguridad As New BLL_Administracion
                Seguridad.Set_Transaccion_Insert(Nothing, 100401, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Consulta Pagina Movil", "/Pagina|" + My.Request.Url.Segments(My.Request.Url.Segments.Length - 1).ToString))
            End Using
        End If
    End Sub

    Private Sub CargarEventos(ByVal nUniOrgCodigo As Integer)
        Dim ldr As New List(Of IDataReader)
        Dim salto_linea As String = Chr(13) + Chr(10)
        Dim empieza_noticias As String = salto_linea + "<table width=100% border=0 cellspacing=0 cellpadding=0>" + salto_linea
        Dim centro_noticias As String = ""
        Dim fin_noticias As String = "</table>" + salto_linea
        Dim anioimpr As String = ""
        Dim mestxt As String = ""

        Using ObjPool As New PoolDbCommand()
            Dim ObjUsuario As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjUsuario.Get_Eventos_By_NuniOrgcodigo(nUniOrgCodigo, 84010209, 10), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldr, True)
            ObjUsuario = Nothing
            While ldr(0).Read
                mestxt = Month(ldr(0).Item("dFechaFin").ToString)
                If mestxt = 1 Then
                    mestxt = "Ene"
                ElseIf mestxt = 2 Then
                    mestxt = "Feb"
                ElseIf mestxt = 3 Then
                    mestxt = "Mar"
                ElseIf mestxt = 4 Then
                    mestxt = "Abr"
                ElseIf mestxt = 5 Then
                    mestxt = "May"
                ElseIf mestxt = 6 Then
                    mestxt = "Jun"
                ElseIf mestxt = 7 Then
                    mestxt = "Jul"
                ElseIf mestxt = 8 Then
                    mestxt = "Ago"
                ElseIf mestxt = 9 Then
                    mestxt = "Sep"
                ElseIf mestxt = 10 Then
                    mestxt = "Oct"
                ElseIf mestxt = 11 Then
                    mestxt = "Nov"
                ElseIf mestxt = 12 Then
                    mestxt = "Dic"
                End If

                centro_noticias = centro_noticias + "<tr><td class=evento align='center' valign='middle'><div>" + Day(ldr(0).Item("dFechaFin").ToString).ToString + "<br><font>" + mestxt + anioimpr + "</font></div></td> <td valign='middle'><a href='./PA_Eventos_Det.aspx?nUniOrgCodigo=" + nUniOrgCodigo.ToString + "&cDocCodigo=" + ldr(0).Item("Codigo").ToString + "&cPerCodigo=" + lblcPercodigo.Text + "'>" + ldr(0).Item("Titulo").ToString + "</a></td></tr>" + salto_linea
            End While
            If centro_noticias <> "" Then
                LabelListaEventos.Text = empieza_noticias + centro_noticias + fin_noticias
            Else
                centro_noticias = "<tr><td>No hay eventos registrados.</td></tr>"
                LabelListaEventos.Text = empieza_noticias + centro_noticias + fin_noticias
            End If
        End Using
    End Sub

    Private Sub CargarEventos_Detalle(ByVal cDocCodigo As String)
        Dim ldr As New List(Of IDataReader)
        Dim salto_linea As String = Chr(13) + Chr(10)
        Dim centro As String = ""
        Dim diatxt As String = ""
        Dim mestxt As String = ""
        Dim aniotxt As String = ""

        Using ObjPool As New PoolDbCommand()
            Dim ObjUsuario As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjUsuario.Get_Eventos_By_cDocCodigo(cDocCodigo), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldr, True)
            ObjUsuario = Nothing
            While ldr(0).Read

                diatxt = Day(ldr(0).Item("dFechaFin").ToString).ToString + " de"
                mestxt = Month(ldr(0).Item("dFechaFin").ToString)
                If mestxt = 1 Then
                    mestxt = " Enero"
                ElseIf mestxt = 2 Then
                    mestxt = " Febrero"
                ElseIf mestxt = 3 Then
                    mestxt = " Marzo"
                ElseIf mestxt = 4 Then
                    mestxt = " Abril"
                ElseIf mestxt = 5 Then
                    mestxt = " Mayo"
                ElseIf mestxt = 6 Then
                    mestxt = " Junio"
                ElseIf mestxt = 7 Then
                    mestxt = " Julio"
                ElseIf mestxt = 8 Then
                    mestxt = " Agosto"
                ElseIf mestxt = 9 Then
                    mestxt = " Septiembre"
                ElseIf mestxt = 10 Then
                    mestxt = " Octubre"
                ElseIf mestxt = 11 Then
                    mestxt = " Noviembre"
                ElseIf mestxt = 12 Then
                    mestxt = " Diciembre"
                End If

                centro = centro + "<div id=noticia><div id=titulo>" + ldr(0).Item("Titulo").ToString + "</div><div id=publicado style='color:#0092CC; font-size:12px;'><b>Programado para el " + diatxt + mestxt + aniotxt + "</b></div>" + salto_linea + "<div id=resumen>" + ldr(0).Item("Resumen").ToString + "</div>" + salto_linea + "<div id=imagen><img src='http://ucvvirtual.edu.pe/imagenes_notieventos/" + ldr(0).Item("Imagen").ToString + "' width=246 height=138 border=0 /></a></div>" + salto_linea + "<div id=contenido>" + ldr(0).Item("Cuerpo").ToString + "</div></div>"
            End While
        End Using
        If centro <> "" Then
            Labelnoticia.Text = centro
        Else
            Labelnoticia.Text = "<div>No hay detalle del evento</div>"
        End If
    End Sub
End Class
